/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hu
 * Date: 2024-05-03
 * Time: 21:24
 */
public class Test {
    public class Test6 {
        public static void main(String[] args) {
            hanoi(3, 'A', 'B', 'C');
        }

        /**
         * 将盘子从pos1移动到pos2
         *
         * @param pos1 起始柱子
         * @param pos2 结束柱子
         */
        public static void move(char pos1, char pos2) {
            System.out.print(pos1 + "->" + pos2 + " ");
        }

        /**
         * @param n    盘子个数
         * @param pos1 起始柱子
         * @param pos2 中转柱子
         * @param pos3 目标柱子
         */
        public static void hanoi(int n, char pos1, char pos2, char pos3) {
            if (n == 1) {
                move(pos1, pos3);
                return;
            } else {
                hanoi(n - 1, pos1, pos3, pos2);
                move(pos1, pos3);
                hanoi(n - 1, pos2, pos1, pos3);
            }
        }
    }
}
